#include<iostream>
using namespace std;
void swap(int* a, int* b)
{
	int tmp = *a;
	*a = *b;
	*b = tmp;

}
void adjustup(int*a,int child)   //向上调整
{
	int parent = (child - 1) / 2;
	while (child > 0)
	{
		if (a[child] < a[parent])
		{
			swap(&a[child], &a[parent]);
			child = parent;
			parent = (child - 1) / 2;

		}
		else
		{
			break;

		}
		

	}


}
void adjustdown(int*a,int parent,int n)//大向下
{
	int child = parent * 2 + 1;
	while (child < n)
	{
	
	
		if (child + 1 < n && a[child] > a[child + 1])
		{

			child += 1;


		}
		if (a[child] < a[parent])
		{
			swap(&a[child], &a[parent]);
			parent = child;
			child = parent * 2 + 1;

		}
		else
		{
			break;
		}
	}




}






void heapsort(int*a,int n)
{

	for (int i = (n - 1 - 1) / 2; i >= 0; i--)
	{
		adjustdown(a, i, n);


	}

	int end = n-1;
	while (end >= 0)
	{
		swap(&a[0],&a[end]);
		adjustdown(a, 0, end);
		end--;



	}



}






int main()
{
int arr[10] = { 95,87,63,16,28,67,33,55,12,10 };
heapsort(arr, 10);
for (int i = 0; i < 10; i++)
{

	cout << arr[i] << " ";


}





}